home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n6.arc / L3.C < prev    next >
Text File  |  1991-01-21  |  1KB  |  38 lines

  1. /* Program to exercise buffer-search routines in Listings 1 & 2 */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define DISPLAY_LENGTH  40
  7.  
  8. extern unsigned char * FindString(unsigned char *, unsigned int,
  9.       unsigned char *, unsigned int, unsigned int);
  10. void main(void);
  11.  
  12. static unsigned char TestBuffer[] = "When, in the course of human \
  13. events, it becomes necessary for one people to dissolve the \
  14. political bands which have connected them with another, and to \
  15. assume among the powers of the earth the separate and equal station \
  16. to which the laws of nature and of nature's God entitle them...";
  17.  
  18. void main() {
  19.    static unsigned char TestString[] = "equal";
  20.    unsigned char TempBuffer[DISPLAY_LENGTH+1];
  21.    unsigned char *MatchPtr;
  22.  
  23.    /* Search for TestString and report the results */
  24.    if ((MatchPtr = FindString(TestBuffer,
  25.          (unsigned int) strlen(TestBuffer), TestString,
  26.          (unsigned int) strlen(TestString), 1)) == NULL) {
  27.       /* TestString wasn't found */
  28.       printf("\"%s\" not found\n", TestString);
  29.    } else {
  30.       /* TestString was found. Zero-terminate TempBuffer; strncpy
  31.          won't do it if DISPLAY_LENGTH characters are copied */
  32.       TempBuffer[DISPLAY_LENGTH] = 0;
  33.       printf("\"%s\" found. Next %d characters at match:\n\"%s\"\n",
  34.             TestString, DISPLAY_LENGTH,
  35.             strncpy(TempBuffer, MatchPtr, DISPLAY_LENGTH));
  36.    }
  37. }
  38.